// index.js
// 获取应用实例
//Page Object
Page({
    data: {
        data:{},
        dateYear: '2021',
        date: '05月',
        pay: {
            title: '支出:',
            num: 180
        },
        income: {
            title: '收入:',
            num: 180
        },
        detailList: [{
            date: '04月01日',
            week: '星期五',
            pay: '支出',
            payNum: 180,
            income: '收入',
            incomeNum: 180,
            detail: [{
                icon: '../../images/bill.png',
                type: '外卖',
                price: '-18.7'
            }, {
                icon: '../../images/bill.png',
                type: '外卖',
                price: '-18.7'
            }]
        },
            {
                date: '04月01日',
                week: '星期五',
                pay: '支出',
                payNum: 180,
                income: '收入',
                incomeNum: 180,
                detail: [{
                    icon: '../../images/bill.png',
                    type: '外卖',
                    price: '-18.7'
                }, {
                    icon: '../../images/bill.png',
                    type: '外卖',
                    price: '-18.7'
                }]
            }
        ]
    },
    //选择框内容改变之后执行的操作
    bindDateChange: function (e) {
        var dateMonth = e.detail.value.substring(5, 7) + "月";
        var year = e.detail.value.substring(0, 4);
        this.setData({
            date: dateMonth,
            dateYear: year
        })
    },
    //options(Object)
    onLoad: function (options) {
        //计算当前的年份月份并赋值给页面
        var date = new Date();
        var nYear = date.getFullYear();
        var nMonth = date.getMonth() + 1;
        if (nMonth < 10) {
            nMonth = "0" + nMonth + "月";
        } else {
            nMonth = nMonth + "月";
        }
        this.setData({
            date: nMonth,
            dateYear: nYear
        })
    },
    onReady: function () {

    },
    onShow: function () {
        var that=this
        wx.request({
            url: 'http://www.lll.plus:8088/details/', //仅为示例，并非真实的接口地址
            method: 'POST',
            data: {
                uid: '1111',
                year: that.data.date,
                month: that.data.dateYear
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            dataType: 'json',
            success(res) {
                console.log(res.data)
                that.setData({data:res.data.data})
                console.log(that.data.data)
            }
        })
    },
    onHide: function () {

    },
    onUnload: function () {

    },
    onPullDownRefresh: function () {

    },
    onReachBottom: function () {

    },
    onShareAppMessage: function () {

    },
    onPageScroll: function () {

    },
    //item(index,pagePath,text)
    onTabItemTap: function (item) {

    }
});